package com.nuc.zyt.Dao.Impl;

import com.nuc.zyt.Dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @ClassName AccountDaoImpl
 * @Description TODO 模拟银行转账事务
 * @Author 耀酱
 * @Date 2023/6/8 10:26
 * @Version 1.0
 */
@Repository
public class AccountDaoImpl implements AccountDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void addAccount() {
        String sql = "update account set account = account - 50 where id = ?";
        int update = jdbcTemplate.update(sql, 1);
    }

    @Override
    public void reduceAccount() {
        String sql = "update account set account = account + 50 where id = ?";
        jdbcTemplate.update(sql,2);
    }
}
